﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace Webchatting.Dal
{
    /// <summary>
    /// 消息发送类
    /// </summary>
    public class SendMessages
    {
        #region 变量
        public static readonly string connStr = @"server=.\SQLEXPRESS;database=ChattingDB;uid=sa;pwd=6341006;Pooling=true;MAX Pool Size=512;Min Pool Size=50;Connection Lifetime=60";
        public SqlConnection ConnSql
        {
            set;
            get;
        }
        #endregion

        /// <summary>
        /// 构造函数，用于初始化 
        /// </summary>
        public SendMessages()
        {
            //初始化数据库连接
            this.ConnSql = new SqlConnection(connStr);
        }

        public int SendFriendsMessagesMethod(int FRUId, int RUId, string msgContent, string RUNickName)
        {
            
            SqlParameter[] sqlParams = new SqlParameter[4];
            sqlParams[0] = new SqlParameter("@RUId", RUId);
           
            sqlParams[1] = new SqlParameter("@RUMToRUId", FRUId);
            sqlParams[2] = new SqlParameter("@RUMContent", msgContent);
            sqlParams[3] = new SqlParameter("@RUNickName", RUNickName);
            
           
            return SqlHelper.ExecuteNonQuery(ConnSql, "spSendFriendsMessages", sqlParams);
        }

        //发送群消息
        public int SendGroupMessagesMethod(int GroupId, string groupmsgContent, int RUId, string RUGroupRemarkName) 
        {
            SqlParameter[] sqlParams = new SqlParameter[4];
           
            sqlParams[0] = new SqlParameter("@GroupId", GroupId);
            
            sqlParams[1] = new SqlParameter("@GMContent", groupmsgContent);
            sqlParams[2] = new SqlParameter("@RUId", RUId);
            sqlParams[3] = new SqlParameter("@RUGroupRemarkName", RUGroupRemarkName);
            
            return SqlHelper.ExecuteNonQuery(ConnSql, "spSendGroupsMessages", sqlParams);
        }
        
        

      
    }
}